package panel.viewSpots
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import inerface.IComment;
	
	import main.ClientConstants;
	import flash.geom.Rectangle;
	
	public class CommentPanel extends Sprite implements IComment
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		
		private var _linkText:TextField = new TextField();
		private var _commentBtn:BtnCloureeComment;
		private var _onOpenInsertComment:Function;
		private var _dragContainer:Sprite = new Sprite();
		public function CommentPanel()
		{
			super();
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			
			_linkText.autoSize = "left";
			_linkText.visible = false;
			this.addChild(_linkText);
			
//			_likeBtn = new BtnCloureeComment(loaztage.stageHeight * ClientConstants.HOME_DOWN_PER - _likeBtn.height;
			_commentBtn = new BtnCloureeComment(loader,stage);
			_commentBtn.show("我来评论！",0);
			_commentBtn.y =  _stage.stageHeight - _stage.stageHeight * ClientConstants.HOME_DOWN_PER - _commentBtn.height;
			_commentBtn.x = _stage.stageWidth * 0.1;
			_commentBtn.addEventListener(MouseEvent.CLICK,clickCommentHandler);
			_dragContainer.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			this.addChild(_dragContainer);
//			this.addChild(_likeBtn);
			this.addChild(_commentBtn);
		}
		
		protected function clickCommentHandler(event:MouseEvent):void
		{
			_onOpenInsertComment();
		}
		
		public function show(dataList:Array):void
		{
			_dragContainer.removeChildren();
			if(!dataList || dataList.length == 0)
			{
				_linkText.visible = true;
				TextFieldUtils.setHtmlText(_linkText,HtmlText.formatSizeColor("还没有人评论，赶紧抢个沙发吧",0xffffff,24));
				_linkText.x = (_stage.stageWidth - _linkText.width) * 0.5;
				_linkText.y = (_stage.stageHeight - _linkText.height) * 0.5;
			}else
			{
				
			for(var i:int=0;i<dataList.length;i++)
			{
				_linkText.visible = false;
				var item:CommentItem = new CommentItem(_loader,_stage);
				item.y = item.height * 1.2 * i;
				item.x = (_stage.stageWidth - item.width) * 0.5;
				item.show(dataList[i]);
				_dragContainer.addChild(item);
			}
			StaticSlide.beginSlide(_dragContainer,_stage,new Rectangle(0,_dragContainer.y,0,-item.height * 1.2 * dataList.length + _dragContainer.y));
			}
		}
		
		public function set onOpenInsertComment(value:Function):void
		{
			_onOpenInsertComment = value;
		}
		
		public function clear():void
		{
//			_dragContainer.removeChildren();
		}
	}
}